package com.bawei.controller;


import com.bawei.pojo.Overtime;
import com.bawei.pojo.UserInfo;
import com.bawei.service.OvertimeService;
import com.bawei.util.PageView;
import com.bawei.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("overtime")
public class OvertimeController {


    @Autowired
    private OvertimeService overtimeService;
    @RequestMapping("list")
    public String overtimeList(Model model, @RequestParam(defaultValue = "1") String currentPage,@RequestParam(defaultValue = "") String realName){
        List<UserInfo> userInfoList=overtimeService.RealNameLike(realName);
        PageView<Overtime> pageView=overtimeService.overtimeList(currentPage,userInfoList);
        model.addAttribute("pageView", pageView);
        return "forward:/system/overtime.jsp";
    }


    @RequestMapping("add")
    @ResponseBody
    public ResultEntity add(String startTime, String endTime, String des, HttpSession session){
        UserInfo userInfo= (UserInfo) session.getAttribute("user");
        ResultEntity resultEntity=overtimeService.add(startTime,endTime,des,userInfo.getId());
        return  resultEntity;
    }

    @RequestMapping("update")
    @ResponseBody
    public ResultEntity update(String id,String startTime, String endTime, String des){
        ResultEntity resultEntity=overtimeService.update(id,startTime,endTime,des);
        return  resultEntity;
    }

    @RequestMapping("detail")
    @ResponseBody
    public Overtime detail(String id){
        return overtimeService.detail(id);

    }
    @RequestMapping("delete")
    @ResponseBody
    public ResultEntity delete(String ids){
        ResultEntity resultEntity=overtimeService.delete(ids);
        return  resultEntity;

    }
}
